<template>
  <div class="report-time">
    <span>报表时间:</span>
    <el-date-picker
      v-model="reportTimeValue"
      type="month"
      popper-class="date-style"
      size="small"
      value-format="yyyy-MM"
      placeholder="请选择"
      @change="changePickerYear"
    />

    <el-button class="specialButton" size="small" @click="reportLook">查看</el-button>
    <el-button class="specialButton" size="small" :loading="dowmLoading" @click="reportDown">下载</el-button>
  </div>
</template>

<script>
// import { Message } from 'element-ui';
export default {
  name: 'ReportTime',
  // props: {
  // reportTimeTitle
  // },
  data() {
    return {
      reportTimeValue: localStorage.getItem('chooseYear') + '-' + (new Date().getMonth() + 1),
      dowmLoading: false
    };
  },
  created() {
    this.reportTimeChange();
  },
  methods: {
    reportTimeChange() {
      this.$emit('reportTimeChange', this.reportTimeValue);
    },
    changePickerYear() {
      if (this.reportTimeValue) {
        this.reportTimeValue = localStorage.getItem('chooseYear') + '-' + this.reportTimeValue.split('-')[1];
      }
    },
    reportLook() {
      this.reportTimeValue ? this.$emit('lookTable') : this.$message.warning('请选择报表时间');
    },
    reportDown() {
      if (!this.reportTimeValue) {
        this.$message.error('请选择报表时间');
      } else {
        this.dowmLoading = true;
        this.$emit('reportDown');
        setTimeout(() => {
          this.dowmLoading = false;
        }, 1000);
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.report-time{
  // ::v-deep .el-button {
  //   color: #1890ff;
  //   border-color: #1890ff;
  // }
  & :nth-child(3){
    margin-left: 30px;
  }
}
.specialButton {
  background: #ffffff;
  border: 1px solid #1890ff;
  border-radius: 3px;
  color: #1890ff;
}
</style>
